﻿using Ducu.BLL.Entity;
using Ducu.GLB.Global;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ducu.SRV.Query
{
    public static class OnTask
    {
        public static IQueryable<Task> GetByDate(this IQueryable<Task> source, 
            DateTime date, Plan plan)
        {
            return source.GetByPlan(plan)
                .Where(t => t.CompleteDate == date)
                ;
        }

        public static IQueryable<Task> GetNeedAccepted(
            this IQueryable<Task> source, User supervisor)
        {
            return source
                .Where(t => t.Status == Status.WaitAccept || t.Status == Status.Resume)
                .Where(t => t.Plan.Supervisors.Contains(supervisor))
                ;
        }

        public static IQueryable<Task> GetNeedAccepted(
            this IQueryable<Task> source, User supervisor, int planId)
        {
            return source.GetNeedAccepted(supervisor)
                .Where(t=>t.Plan.Id == planId)
                ;
        }

        public static IQueryable<Task> GetNeedAccepted(
            this IQueryable<Task> source, Plan plan)
        {
            return source.Where(t => t.Plan == plan)
                ;
        }

        public static IQueryable<Task> GetByPlan(
            this IQueryable<Task> source, Plan plan)
        {
            return source.Where(t => t.Plan == plan)
                ;        
        }

        public static IQueryable<Task> Between(this IQueryable<Task> source, 
            DateTime from, DateTime to)
        {
            return source.Where(t => t.CompleteDate > from && t.CompleteDate <= to);
        }

        public static IQueryable<Task> HasLeft(this IQueryable<Task> source)
        {
            return source.Where(t => t.Status == Status.Leave);
        }
    }
}
